package fiscal.dao;

import java.util.ArrayList;
import java.util.Collection;

import javax.persistence.Query;

import exceptions.PersistenceExceptionMessage;
import fiscal.entities.tables.PisCofins;
import generic.dao.GenericDAO;

public class PersistencePisCofins extends GenericDAO<PisCofins, String>{

	@Override
	public Class<PisCofins> getCurrentClass() {
		return PisCofins.class;
	}

	@SuppressWarnings("unchecked")
	public Collection<PisCofins> findAllByEntrada() throws PersistenceExceptionMessage {
		if (getEntityManager() != null) {
			Query query = getEntityManager().createQuery("SELECT c FROM " +getCurrentClass().getName() 
					+" c WHERE c.sentido = :sentido ORDER BY c.codigo");
			query.setParameter("sentido", 'E');
			
			return query.getResultList();
		}
		return new ArrayList<PisCofins>();
	}
	
	@SuppressWarnings("unchecked")
	public Collection<PisCofins> findAllBySaida() throws PersistenceExceptionMessage {
		if (getEntityManager() != null) {
			Query query = getEntityManager().createQuery("SELECT c FROM " +getCurrentClass().getName() 
					+" c WHERE c.sentido = :sentido ORDER BY c.codigo");
			query.setParameter("sentido", 'S');
	
			return query.getResultList();
		}
		return new ArrayList<PisCofins>();
	}
}
